# @Time    : 2024/12/31 15:23
# @Author  : Zhang Yihao
import os
from time import strftime
from time import  gmtime


def change_dir():
    """
    改变路径
    :return:
    """
    print(os.getcwd())
    os.chdir('dir2')
    print(os.getcwd())

def scan_dir(current_path,width):
    """
    深度优先遍历
    """
    file_list=os.listdir(current_path)#获取当前路径下的文件列表
    for file in file_list:
        print(' ' * width,file)
        new_path=current_path+'/'+file
        if os.path.isdir(new_path):
            scan_dir(new_path,width+4)

def use_stat(file_path):
    file_info=os.stat(file_path)
    print('size:{},uid:{},mode:{:x},mtime:{}'.format(file_info.st_size,file_info.st_uid,file_info.st_mode,file_info.st_mtime))
    gm_time=gmtime(file_info.st_mtime)
    print(strftime('%Y-%m-%d %H:%M:%S',gm_time))

if __name__ == '__main__':
    # change_dir()
    # scan_dir('.',4)
    use_stat('file1')
